<?php

namespace framework\support;

class Response
{
    static function Success($data = null)
    {
        self::Error(0, 'ok', $data);
    }

    static function Error($code, $msg = "", $data = null)
    {
        header('Content-Type: application/json; charset=utf-8');
        $res = [
            'code' => $code,
            'msg' => $msg,
        ];
        if ($data) {
            $res['data'] = $data;
        }
        echo json_encode($res);
        return;
    }

    static function Redirect($url)
    {
        header('Location: ' . $url);
    }

    static function Raw($httpCode, $data = null)
    {
        header('Content-Type: application/json; charset=utf-8');
        header('HTTP/1.1 ' . $httpCode);
        echo $data;
    }
}
